package com.lantu.wisdom.common.utils;

import com.lantu.framework.common.constants.exceptions.ASException;
import com.odianyun.util.sensi.SensitiveFilter;

import java.util.List;

/**
 * @Description :
 * @Author: duhui
 * @Date: 2020/8/14 9:55
 */
public class SensitiveWordUtil {

    // 使用默认单例（加载默认词典）
    public static SensitiveFilter filter = SensitiveFilter.DEFAULT;
    public static void main(String[] s) {

        // 待过滤的句子
        String sentence = "然后，市长在婚礼上唱春天在哪里。肉棒插入小穴 日你妹";
        // 进行过滤
        List<String> filted = SensitiveWordUtil.sensitiveWord(sentence);

        // 如果未过滤，则返回输入的String引用
        System.out.println(filted.toString());

    }

    public static List<String> paramSensitiveWord(String text) throws ASException {
        List<String> list = filter.filter(text, '*');
        if(0!=list.size()){
            throw  new ASException("参数包含敏感词"+list.toString());
        }
        return list;
    }

    public static List<String> sensitiveWord(String text) throws ASException {
        return filter.filter(text, '*');
    }
}
